package com.baizhi.enumeration3;

import java.util.Scanner;

public class ShapeTest {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        System.out.println("请输入图形名称：");
        String shapeName = scan.next();


        Shape s = null; //声明一个变量用于接受用户输入的图形

        //获取所有图形
        Shape[] shapes = Shape.values();
        //遍历每一个图形元素，获取图形名称
        for (int i = 0; i < shapes.length; i++) {
            Shape shape = shapes[i]; //获取每一个图形元素
            String name = shape.getShapeName(); //获取图形名称
            if (name.equals(shapeName)) {
                s = shape;
            }
        }


        switch (s) {
            case SQUARE:
                System.out.println("请输入正方形的宽");
                double width = scan.nextDouble();
                s.setWidth(width); //将用户输入的宽赋值给正方形
                System.out.println("正方形的面积是：" + (s.getWidth() * s.getWidth()));
                break;
            case RECTANGLE:
                System.out.println("请输入长方形的宽");
                s.setWidth(scan.nextDouble());
                System.out.println("请输入长方形的高");
                s.setHeight(scan.nextDouble());
                System.out.println("长方形的面积是：" + (s.getWidth() * s.getHeight()));
                break;
            case TRIANGLE:
                System.out.println("请输入三角形的底边");
                s.setWidth(scan.nextDouble());
                System.out.println("请输入三角形的高");
                s.setHeight(scan.nextDouble());
                System.out.println("三角形的面积是：" + (s.getWidth() * s.getHeight() / 2));
                break;

        }


    }
}
